#include <stdlib.h>
#include "buffer.h"
#include <string.h>


void set_at(Buffer buffer, size_t ix, double val)
{
    double *dp = (double*)buffer.buf;
    dp += ix;
    *dp = val;
}

void buf_push(Buffer buffer, double val)
{
    if (buffer.pos == buffer.sz)
    {
        void *newBuf = malloc(buffer.sz * 2 * 8);
        memset(newBuf, 0, buffer.sz * 2 * 8);
        memcpy(newBuf, buffer.buf, buffer.sz * 8);
        free(buffer.buf);
        buffer.buf = newBuf;
        buffer.sz *= 2;
    }
    double *dp = (double*)buffer.buf;
    dp += buffer.pos;
    *dp = val;
    ++buffer.pos;
}
